package org.me.SendSMS;


import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.me.SendSMS.adapter.RepeatDateAdapter;
import org.me.SendSMS.data.Model;
import org.me.SendSMS.utli.GlobalVariable;

import com.google.android.apps.analytics.GoogleAnalyticsTracker;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;

public class RepeatDateActivity extends Activity implements OnClickListener{
	private List<Model> list = new ArrayList<Model>();
	private RepeatDateAdapter adapter;
	private Context mContext;
	private ListView listviewDate;
	private GoogleAnalyticsTracker tracker;
	private Button btnSet,btnCancel;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		 tracker = GoogleAnalyticsTracker.getInstance();
	     // Start the tracker in manual dispatch mode...
	    tracker.startNewSession("UA-35081259-1", getApplication());
		setContentView(R.layout.listview_repeat_date);
		mContext 		= this;
		
		btnSet			= (Button)findViewById(R.id.btnSetRepeate);
		btnCancel		= (Button)findViewById(R.id.btnCancelRepeate);
		
		btnSet.setOnClickListener(this);
		btnCancel.setOnClickListener(this);
		
		listviewDate 	= (ListView)findViewById(R.id.listDate);
		adapter 		= new RepeatDateAdapter(mContext, getModel());
		listviewDate.setAdapter(adapter);
	}
	
	private List<Model> getModel() {
        list.add(new Model("Monday",0));
        list.add(new Model("Tuesday",1));
        list.add(new Model("Wednesday",2));
        list.add(new Model("Thursday",3));
        list.add(new Model("Friday",4));
        list.add(new Model("Saturday",5));
        list.add(new Model("Sunday",6));
        return list;
    }

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.btnSetRepeate:
			GlobalVariable.START_DATE_REPEAT = true;
			
			Collections.sort(GlobalVariable.arrID, new Comparator<String>() {
	    		  
				
				@Override
				public int compare(String o1, String o2) {
					// TODO Auto-generated method stub
					return o1.compareTo(o2);
				}
	    		});
			
			
			String string = "";
			Log.w("aaaaaaaaaaaaaa", "GlobalVariable.arrID = "+GlobalVariable.arrID);
			for(int i = 0; i<GlobalVariable.arrID.size(); i++)
			{
				if(i<GlobalVariable.arrID.size()-1)
				{
					string +=GlobalVariable.arrID.get(i).substring(1,4)+",";
				}
				else
				{
					if(i ==GlobalVariable.arrID.size()-1)
						string +=GlobalVariable.arrID.get(i).substring(1,4);
				}
			}
			GlobalVariable.ARRAY_ID = string;
			Log.w("aaaaaaaaaaaaaa", "GlobalVariable.ARRAY_ID = "+GlobalVariable.ARRAY_ID);
			
			GlobalVariable.SetDefaultData(mContext, GlobalVariable.dateRepeat, GlobalVariable.ARRAY_ID);
			
			
			finish();
			
			break;
		case R.id.btnCancelRepeate:
			finish();
			break;

		default:
			break;
		}
		
	}
}
